package com.tjetc.view.adminview;

import com.tjetc.proxy.CilentProxy;
import com.zhiyun.domain.QuestionType;
import com.zhiyun.service.QuestionTypeService;
import com.zhiyun.vo.Result;

import java.util.List;
import java.util.Scanner;

public class Admins_Exams {
    QuestionTypeService questionTypeService= CilentProxy.getProxyInstance(QuestionTypeService.class);
    Scanner scanner=new Scanner(System.in);
    public void start() {
        while (true){
            System.out.println("~~~~~~~~~题目类型管理~~~~~~~~~");
            System.out.println("1. 查询题目类型");
            System.out.println("2. 增加题目类型");
            System.out.println("3. 删除题目类型");
            System.out.println("4. 修改题目类型");
            System.out.println("0. 退出");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    alls();
                    break;
                case 2:
                    ins();
                    break;
                case 3:
                    delt();
                    break;
                case 4:
                    upd();
                    return;
                case 0:

                    return;
                default:
                    break;
            }
        }
    }

    private void alls() {
        while (true){
            Result allQuestionType = questionTypeService.findAllQuestionType();
            if (allQuestionType.getCode()==200){
                List<QuestionType> obj = (List<QuestionType>) allQuestionType.getObj();
                for (QuestionType questionType : obj) {
                    System.out.println(questionType.getId()+"    "+questionType.getName());
                }
            }else {
                System.out.println("获取失败");
            }
            break;
        }
    }

    private void ins() {
        while (true){
            System.out.println("请输入题目类型");
            String next = scanner.next();
            Result result = questionTypeService.insertQuestionType(new QuestionType(0, next));
            if (result.getCode()==200){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
            break;
        }
    }

    private void delt() {
        while (true){
            Result allQuestionType = questionTypeService.findAllQuestionType();
            if (allQuestionType.getCode()==200){
                List<QuestionType> obj = (List<QuestionType>) allQuestionType.getObj();
                for (QuestionType questionType : obj) {
                    System.out.println(questionType);
                }
                System.out.println("请输入想要删除的题目类型id");
                int i = scanner.nextInt();
                Result result = questionTypeService.delQuestionType(i);
                if (result.getCode()==200){
                    System.out.println("删除成功");
                }else {
                    System.out.println("删除失败");
                }
            }else {
                System.out.println("获取失败");
            }
           break;
        }
    }

    private void upd() {
        while (true){
            Result allQuestionType = questionTypeService.findAllQuestionType();
            if (allQuestionType.getCode()==200){
                List<QuestionType> obj = (List<QuestionType>) allQuestionType.getObj();
                for (QuestionType questionType : obj) {
                    System.out.println(questionType.getId()+"    "+questionType.getName());
                }
                System.out.println("请输入想要修改的题目类型id");
                int i = scanner.nextInt();
                System.out.println("请输入修改后的题目名称");
                String name = scanner.next();
                Result result = questionTypeService.updateQuestionType(new QuestionType(i,name));
                if (result.getCode()==200){
                    System.out.println("修改成功");
                }else {
                    System.out.println("修改失败");
                }
            }else {
                System.out.println("获取失败");
            }
            break;
        }
    }
}
